package com.ddwl.goods.controller.bargain;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.bargain.BargainActivityService;
import com.ddwl.goods.service.bargain.BargainItemService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.bargain.BargainActivityAddBo;
import com.ddwl.schema.bo.goods.bargain.BargainActivityPageBo;
import com.ddwl.schema.bo.goods.bargain.BargainActivityStatusBo;
import com.ddwl.schema.bo.goods.bargain.BargainActivityUpdateBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.bargain.BargainActivityDetailVo;
import com.ddwl.schema.vo.goods.bargain.BargainActivityItemVo;
import com.ddwl.schema.vo.goods.bargain.BargainActivityVo;
import com.ddwl.schema.vo.goods.bargain.BargainSkuDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2020/10/23 17:05
 */
@RestController
@RequestMapping("/bargainActivity")
@Api(tags = "砍价活动")
public class BargainActivityController extends BaseController {

    @Resource
    private BargainActivityService bargainActivityService;
    @Resource
    private BargainItemService bargainItemService;

    @PostMapping("/add")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("新增砍价活动")
    public RestVo addBargainActivity(@RequestBody @Valid BargainActivityAddBo bo) {
        bargainActivityService.add(bo, getProduct());
        return RestVo.ok();
    }

    @PostMapping("/update")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("修改砍价活动")
    public RestVo updateBargainActivity(@RequestBody @Valid BargainActivityUpdateBo bo) {
        bargainActivityService.update(bo);
        return RestVo.ok();
    }

    @GetMapping("/{id}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("获取砍价活动详情")
    public RestVo<BargainActivityDetailVo> getBargainActivityDetail(@PathVariable("id") String id) {
        return RestVo.ok(bargainItemService.getDetailById(id));
    }

    @DeleteMapping("/{id}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("删除砍价活动")
    public RestVo deleteBargainActivity(@PathVariable("id") String id) {
        bargainActivityService.delete(id);
        return RestVo.ok();
    }

    @PostMapping("/page")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("后台砍价活动分页查询")
    public RestVo<PageVo<BargainActivityVo>> page(@RequestBody PageBo<BargainActivityPageBo> pageBo) {
        return RestVo.ok(bargainActivityService.page(pageBo));
    }

    @PostMapping("/openOrClose")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("后台砍价活动开启或关闭")
    public RestVo openOrClose(@RequestBody BargainActivityStatusBo bo) {
        bargainActivityService.openOrClose(bo);
        return RestVo.ok();
    }

    @PostMapping("/list")
    @ApiOperation("app砍价商品列表")
    public RestVo<PageVo<BargainActivityItemVo>> list(@RequestBody PageBo pageBo) {
        return RestVo.ok(bargainItemService.list(pageBo));
    }

    @GetMapping("/getBargainSku")
    @Auth(product = {BaseEnum.ProductEnum.FENXIAO}, required = false)
    @ApiOperation("app获取商品sku信息")
    public RestVo<List<BargainSkuDetailVo>> getBargainSku(@RequestParam String activityId, @RequestParam String itemId) {
        return RestVo.ok(bargainItemService.getBargainSku(activityId, itemId));
    }


}
